namespace Caltech.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class addSalesmanFieldToCustomer : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.QuoteItems", "EquipmentId", "dbo.Equipment");
            DropForeignKey("dbo.WorkOrderDetails", "EquipmentId", "dbo.Equipment");
            DropPrimaryKey("dbo.Equipment");
            CreateTable(
                "dbo.WorkOrderDetails",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        EquipmentId = c.Int(nullable: false),
                        WorkOrderId = c.Int(nullable: false),
                        CreatedBy = c.String(),
                        CreatedDate = c.DateTime(),
                        UpdatedDate = c.DateTime(),
                        UpdatedBy = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Equipment", t => t.EquipmentId, cascadeDelete: true)
                .ForeignKey("dbo.WorkOrders", t => t.WorkOrderId, cascadeDelete: true)
                .Index(t => t.EquipmentId)
                .Index(t => t.WorkOrderId);
            
            CreateTable(
                "dbo.WorkOrders",
                c => new
                    {
                        WorkOrderId = c.Int(nullable: false, identity: true),
                        WorkOrderNo = c.String(),
                        CustomerId = c.Int(nullable: false),
                        CalibrationCycle = c.String(),
                        CalibrationDate = c.DateTime(nullable: false),
                        NextDueDate = c.DateTime(nullable: false),
                        PONumber = c.String(),
                        SalesmanId = c.String(maxLength: 128),
                        CreatedBy = c.String(),
                        CreatedDate = c.DateTime(),
                        UpdatedDate = c.DateTime(),
                        UpdatedBy = c.String(),
                    })
                .PrimaryKey(t => t.WorkOrderId)
                .ForeignKey("dbo.Customers", t => t.CustomerId, cascadeDelete: true)
                .ForeignKey("dbo.AspNetUsers", t => t.SalesmanId)
                .Index(t => t.CustomerId)
                .Index(t => t.SalesmanId);
            
            AddColumn("dbo.Certificate", "WorkOrderNo", c => c.String());
            AddColumn("dbo.Customers", "Fax", c => c.String());
            AddColumn("dbo.Customers", "NextDueDate", c => c.DateTime());
            AddColumn("dbo.Customers", "SalesmanId", c => c.String(maxLength: 128));
            AddColumn("dbo.Customers", "LoginUsername", c => c.String());
            AddColumn("dbo.Equipment", "Id", c => c.Int(nullable: false, identity: true));
            AddColumn("dbo.Equipment", "CalibrationDate", c => c.DateTime());
            AddColumn("dbo.Equipment", "NextDueDate", c => c.DateTime());
            AddColumn("dbo.Equipment", "Name", c => c.String());
            AddColumn("dbo.Equipment", "CustomerId", c => c.Int());
            AddColumn("dbo.Quotes", "QuoteNumber", c => c.String());
            AlterColumn("dbo.Certificate", "CreatedBy", c => c.String());
            AlterColumn("dbo.Certificate", "UpdatedBy", c => c.String());
            AlterColumn("dbo.CertificateStandard", "CreatedBy", c => c.String());
            AlterColumn("dbo.CertificateStandard", "UpdatedBy", c => c.String());
            AlterColumn("dbo.Customers", "CreatedBy", c => c.String());
            AlterColumn("dbo.Customers", "UpdatedBy", c => c.String());
            AlterColumn("dbo.Equipment", "CreatedBy", c => c.String());
            AlterColumn("dbo.Equipment", "UpdatedBy", c => c.String());
            AlterColumn("dbo.QuoteItems", "CreatedBy", c => c.String());
            AlterColumn("dbo.QuoteItems", "UpdatedBy", c => c.String());
            AlterColumn("dbo.Quotes", "CreatedBy", c => c.String());
            AlterColumn("dbo.Quotes", "UpdatedBy", c => c.String());
            AddPrimaryKey("dbo.Equipment", "Id");
            CreateIndex("dbo.Customers", "SalesmanId");
            CreateIndex("dbo.Equipment", "CustomerId");
            AddForeignKey("dbo.Equipment", "CustomerId", "dbo.Customers", "Id");
            AddForeignKey("dbo.Customers", "SalesmanId", "dbo.AspNetUsers", "Id");
            AddForeignKey("dbo.QuoteItems", "EquipmentId", "dbo.Equipment", "Id", cascadeDelete: true);
            DropColumn("dbo.Equipment", "EquipmentId");
        }
        
        public override void Down()
        {
            AddColumn("dbo.Equipment", "EquipmentId", c => c.Int(nullable: false, identity: true));
            DropForeignKey("dbo.QuoteItems", "EquipmentId", "dbo.Equipment");
            DropForeignKey("dbo.WorkOrderDetails", "WorkOrderId", "dbo.WorkOrders");
            DropForeignKey("dbo.WorkOrders", "SalesmanId", "dbo.AspNetUsers");
            DropForeignKey("dbo.WorkOrders", "CustomerId", "dbo.Customers");
            DropForeignKey("dbo.WorkOrderDetails", "EquipmentId", "dbo.Equipment");
            DropForeignKey("dbo.Customers", "SalesmanId", "dbo.AspNetUsers");
            DropForeignKey("dbo.Equipment", "CustomerId", "dbo.Customers");
            DropIndex("dbo.WorkOrders", new[] { "SalesmanId" });
            DropIndex("dbo.WorkOrders", new[] { "CustomerId" });
            DropIndex("dbo.WorkOrderDetails", new[] { "WorkOrderId" });
            DropIndex("dbo.WorkOrderDetails", new[] { "EquipmentId" });
            DropIndex("dbo.Equipment", new[] { "CustomerId" });
            DropIndex("dbo.Customers", new[] { "SalesmanId" });
            DropPrimaryKey("dbo.Equipment");
            AlterColumn("dbo.Quotes", "UpdatedBy", c => c.Int(nullable: false));
            AlterColumn("dbo.Quotes", "CreatedBy", c => c.Int(nullable: false));
            AlterColumn("dbo.QuoteItems", "UpdatedBy", c => c.Int(nullable: false));
            AlterColumn("dbo.QuoteItems", "CreatedBy", c => c.Int(nullable: false));
            AlterColumn("dbo.Equipment", "UpdatedBy", c => c.Int(nullable: false));
            AlterColumn("dbo.Equipment", "CreatedBy", c => c.Int(nullable: false));
            AlterColumn("dbo.Customers", "UpdatedBy", c => c.Int(nullable: false));
            AlterColumn("dbo.Customers", "CreatedBy", c => c.Int(nullable: false));
            AlterColumn("dbo.CertificateStandard", "UpdatedBy", c => c.Int(nullable: false));
            AlterColumn("dbo.CertificateStandard", "CreatedBy", c => c.Int(nullable: false));
            AlterColumn("dbo.Certificate", "UpdatedBy", c => c.Int(nullable: false));
            AlterColumn("dbo.Certificate", "CreatedBy", c => c.Int(nullable: false));
            DropColumn("dbo.Quotes", "QuoteNumber");
            DropColumn("dbo.Equipment", "CustomerId");
            DropColumn("dbo.Equipment", "Name");
            DropColumn("dbo.Equipment", "NextDueDate");
            DropColumn("dbo.Equipment", "CalibrationDate");
            DropColumn("dbo.Equipment", "Id");
            DropColumn("dbo.Customers", "LoginUsername");
            DropColumn("dbo.Customers", "SalesmanId");
            DropColumn("dbo.Customers", "NextDueDate");
            DropColumn("dbo.Customers", "Fax");
            DropColumn("dbo.Certificate", "WorkOrderNo");
            DropTable("dbo.WorkOrders");
            DropTable("dbo.WorkOrderDetails");
            AddPrimaryKey("dbo.Equipment", "EquipmentId");
            AddForeignKey("dbo.WorkOrderDetails", "EquipmentId", "dbo.Equipment", "Id", cascadeDelete: true);
            AddForeignKey("dbo.QuoteItems", "EquipmentId", "dbo.Equipment", "Id", cascadeDelete: true);
        }
    }
}
